<template>
  <am-topbar :inverse="true" :fixed="true">
    <am-topbar-brand>
      <div class="logo">
        <router-link to="/">
          <am-image v-lazy="'/static/header_logo2.jpg'" :src="''" />
        </router-link>
      </div>
    </am-topbar-brand>

    <am-topbar-toggle></am-topbar-toggle>

    <am-topbar-collapse>
      <am-nav customClass="dg-nav-ul" :pill="true" :topbar="true">
        <am-nav-item v-for="(item, index) in menus" :key="index"
          :to="item.href"
          :active="curIndex === index">
          <span class="am-inline-block">{{ item.name }}</span>
        </am-nav-item>
      </am-nav>

      <am-topbar-slot v-for="(item, index) in btns" :key="index">
        <am-button color="success" custom-class="am-topbar-btn am-btn-sm" v-text="item.name" @click="btnAct(item.act)" v-if="item.act"></am-button>
        <router-link :to="item.href" v-if="item.href">
          <am-button color="success" custom-class="am-topbar-btn am-btn-sm" v-text="item.name"></am-button>
        </router-link>
      </am-topbar-slot>
    </am-topbar-collapse>
  </am-topbar>
</template>

<script>
export default {
  name: 'c-header',
  data() {
    return {
      curIndex: this.$store.state.curIndex || 0,// 当前选中菜单索引
    }
  },
  props: {
    btns: {
      type: Array,
      default() {
        // act or href
        return []
      }
    },
    menus: {
      type: Array,
      default() {
        return [{
          name:'赛事首页',
          href: '/'
        }, {
          name: '大赛作品',
          href: '/game/cur'
        }, {
          name: '大赛设计师',
          href: '/designerList'
        }, {
          name: '大赛获奖',
          href: '/prizeList'
        }];
      }
    }
  },
  methods: {
    btnAct(act) {
      // new Function('that', item.act)(this);
      this.$emit('btnAct', act);
    },
    goBack() {
      // this.$router.go(-1);
      this.$router.go(-1);
    }
  }
}
</script>

<style lang="less" scoped>
.logo {
  height: 100%;
  img {
    height: 100%;
  }
}
</style>